﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TireService.Data
{
    public class TireSetBLL
    {
        public void UpdateTireSet(TireServiceDB db, TireSet tireset, Car car, int TireTypeId, decimal? Size, decimal? Width, decimal? Height, int? TireSpeedIndex, int? TireLoadIndex, int? TireBrand, string TireBrandNote, bool LockingBolt, bool HubCaps, bool RunFlatTire, bool RimProtection, bool ExtraBolts, DateTime? ManufactureDate, int? FromTireSetStatusId, int TireSetStatusId, int? SocketWrenchSize, int? ContainerCargoRoomId, bool DummyTireSet, bool NeedBalancing, DateTime? LastBalancingDate, Guid UserId, string LogNote, bool SubmitInTransaction)
        {
            try
            {
                // Create/Update existing tireset
                car.TireSets.Add(tireset);
                tireset.DummyTireSet = DummyTireSet;
                tireset.TireTypeId = TireTypeId;
                tireset.Size = Size;
                tireset.Width = Width;
                tireset.Height = Height;
                tireset.TireSpeedIndexId = TireSpeedIndex;
                tireset.TireLoadIndexId = TireLoadIndex;
                tireset.TireBrandId = TireBrand;
                tireset.TireBrandNote = TireBrandNote;
                tireset.LockingBolt = LockingBolt;
                tireset.HubCaps = HubCaps;
                tireset.RunFlatTire = RunFlatTire;
                tireset.RimProtection = RimProtection;
                tireset.ExtraBolts = ExtraBolts;
                tireset.ManufactureDate = ManufactureDate;
                tireset.SocketWrenchSize = SocketWrenchSize;
                tireset.ContainerCargoRoomId = ContainerCargoRoomId;
                tireset.TireSetStatusId = TireSetStatusId;
                tireset.NeedBalancing = NeedBalancing;
                tireset.LastBalancingDate = LastBalancingDate;

                // Instantiate business layer
                TireSetLogBLL bll = new TireSetLogBLL();

                // Create tireset log
                bll.CreateTireSetLog(db, tireset, DateTime.Now, FromTireSetStatusId, tireset.TireSetStatusId, UserId, LogNote, null, null, null, null, tireset.ContainerCargoRoomId);

                // Create new car
                if (tireset.TireSetId == 0)
                {
                    db.AddTireSet(tireset);
                }

                // Check if customer is being created/updated in other transaction
                if (!SubmitInTransaction)
                {
                    // Submit changes to database
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {


            }
        }

        public string GetTireDimensions(TireSet tireset)
        {
            return tireset.Width.ToString() + "/" + tireset.Height.ToString() + " " + tireset.Size.ToString();
        }

        public string GetTireDimensions(BusinessTireSetListView tireset)
        {
            return tireset.Width.ToString() + "/" + tireset.Height.ToString() + " " + tireset.Size.ToString();
        }
    }
}
